package top.gangster.lunan.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import top.gangster.lunan.userservice.entity.Department;
import top.gangster.lunan.userservice.entity.vo.DeptVo;
import top.gangster.lunan.userservice.mapper.DepartmentMapper;
import top.gangster.lunan.userservice.service.DepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 公司所含部门信息 服务实现类
 * </p>
 *
 * @author vic
 * @since 2021-11-06
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
  @Autowired
  DepartmentService departmentService;
  @Resource
  DepartmentMapper departmentMapper;

  /**
   * 列表查找部门
   * @param current 当前页
   * @param size 当前页大小
   * @return DeptVo
   */
  @Override
  public DeptVo getDeptList(int current,int size){
    DeptVo deptVo = new DeptVo();
    Page<Department> page = new Page<>(current,size);
    IPage<Department> res = departmentMapper.selectPageDepartmentList(page);
    deptVo.setTotal(page.getTotal());
    deptVo.setDeptList(page.getRecords());
    deptVo.setCurrent(current);
    deptVo.setSize(size);
    return deptVo;
  }

  /**
   * 通过部门名字查找部门
   * @param current 当前页
   * @param size 当前页大小
   * @param deptName 部门名
   * @return DeptVo
   */
  @Override
  public DeptVo getDeptByName(int current,int size,String deptName){
    DeptVo deptVo = new DeptVo();
    Page<Department> page = new Page<>(current,size);
    IPage<Department> res = departmentMapper.selectPageDepartmentByName(page,deptName);
    deptVo.setTotal(page.getTotal());
    deptVo.setDeptList(page.getRecords());
    deptVo.setCurrent(current);
    deptVo.setSize(size);
    return deptVo;
  }

  /**
   * 添加部门
   * @param dept 部门
   * @return DeptVo
   */
  @Override
  public boolean addDept(Department dept){
    return departmentService.save(dept);
  }

  /**
   * 修改部门
   * @param dept 部门
   * @return DeptVo
   */
  @Override
  public boolean modifyDept(Department dept){
    return departmentService.updateById(dept);
  }

  /**
   * 删除部门
   * @param dept 部门
   * @return DeptVo
   */
  @Override
  public boolean deleteDept(Department dept){
    return departmentService.removeById(dept);
  }

  /**
   * 不分页列表查找部门
   * @return List<Department>
   */
  @Override
  public List<Department> getDeptList(){
    QueryWrapper<Department> qw = new QueryWrapper<>();
    return departmentService.list(qw);
  }




}
